/**
 * Copyright 2010 Nicholas Alexander Cross
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dataporter.data;

import org.apache.commons.lang.NullArgumentException;

import java.util.List;
import java.util.Map;

public class DataUpdate {

    private final String entityName;
    private final DataUpdateType type;
    private final List<String> primaryKeys;
    private final Map<String, Object> changes;

    public DataUpdate( String entityName, DataUpdateType type, List<String> primaryKeys, Map<String, Object> changes ) {
        this.entityName = entityName;
        this.type = type;
        this.primaryKeys = primaryKeys;
        this.changes = changes;

        if ( entityName == null )
        {
            throw new NullArgumentException( "entityName" );
        }

        if ( type == null )
        {
            throw new NullArgumentException( "type" );
        }

        if ( changes == null )
        {
            throw new NullArgumentException( "changes" );
        }
        else if ( changes.size() < 1 )
        {
            throw new IllegalArgumentException( "Must specify at least 1 change, or there is nothing to update..." );
        }
    }

    public Map<String, Object> getChanges() {
        return changes;
    }

    public String getEntityName() {
        return entityName;
    }

    public List<String> getPrimaryKeyNames() {
        return primaryKeys;
    }

    public DataUpdateType getUpdateType() {
        return type;
    }
}
